package com.nd.mobile.study.domain;

import java.io.Serializable;

import android.os.Bundle;

import com.fuckhtc.gson.Gson;
import com.fuckhtc.gson.annotations.SerializedName;
import com.fuckhtc.gson.reflect.TypeToken;
import com.nd.mobile.study.common.config.Commands;
import com.nd.mobile.study.common.config.ReqParam;
import com.nd.mobile.study.common.util.HttpRequestUtil;
import com.nd.mobile.study.common.util.L;

public class Subject implements Serializable{
	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;

	@SerializedName("SubjectID")
	private String id;
	
	@SerializedName("SubjectName")
	private String name;

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}
	
	private Bundle prepareReq(User user) {
		Bundle data = new Bundle();
		data.putString(ReqParam.SUBJECT_ID, this.id);
		data.putString(ReqParam.COMMON_USER_ID, user.getUserId());
		return data;
	}
	
	public VideoInfo[] getVideoCatalog(User user) throws Exception{
		String jsonData = HttpRequestUtil.get(Commands.GET_SUBJECT_VIDEO_CATALOG, prepareReq(user));
		Result<VideoInfo[]> result = new Gson().fromJson(jsonData, new TypeToken<Result<VideoInfo[]>>() {
		}.getType());
		VideoInfo[] body = result.getBody();
		return body;
	}
	
	public TextInfoCatalog[] getTextInfoCatalog(User user) throws Exception {
		String jsonData = HttpRequestUtil.get(Commands.GET_SUBJECT_TEXT_CATALOG, prepareReq(user));
		Result<TextInfoCatalog[]> result = new Gson().fromJson(jsonData, new TypeToken<Result<TextInfoCatalog[]>>() {
		}.getType());
		TextInfoCatalog[] body = result.getBody();
		return body;
	}

	public MaterialInfo[] getMaterialInfoCatalog(User user) throws Exception {
		String jsonData = HttpRequestUtil.get(Commands.GET_SUBJECT_MATERIAL_CATALOG, prepareReq(user));
		Result<MaterialInfo[]> result = new Gson().fromJson(jsonData, new TypeToken<Result<MaterialInfo[]>>() {
		}.getType());
		MaterialInfo[] body = result.getBody();
		return body;
	}
	
	public HomeworkQCatalog[] getHomeworkQCatalog(User user) throws Exception {
		String jsonData = HttpRequestUtil.get(Commands.GET_SUBJECT_HOMEWORK_Q_CATALOG, prepareReq(user));
		Result<HomeworkQCatalog[]> result = new Gson().fromJson(jsonData, new TypeToken<Result<HomeworkQCatalog[]>>() {
		}.getType());
		HomeworkQCatalog[] body = result.getBody();
		return body;
	}
	
	public ExamQCatalog[] getExamQCatalog(User user) throws Exception {
		String jsonData = HttpRequestUtil.get(Commands.GET_SUBJECT_HOMEWORK_Q_CATALOG, prepareReq(user));
		Result<ExamQCatalog[]> result = new Gson().fromJson(jsonData, new TypeToken<Result<ExamQCatalog[]>>() {
		}.getType());
		ExamQCatalog[] body = result.getBody();
		return body;
	}
	/***
	 * 获取套卷列表
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public BluebookCatalog[] getBluebookCatalog(User user) throws Exception {
		String jsonData = HttpRequestUtil.get(Commands.GET_SUBJECT_EXAM_Q_CATALOG, prepareReq(user));
//		String jsonData = "{\"ReturnInfo\": ["+
//					"{\"BlueBookID\": \"11\","+
//					"\"BlueBookName\":\"测试\","+
//					"\"TotalScore\":\"10\""+
//					"}],"+
//					"\"PromptInfo\":\"成功\""+ 
//					"}";
		L.i("---BluebookCatalog----", jsonData);
		Result<BluebookCatalog[]> result = new Gson().fromJson(jsonData, new TypeToken<Result<BluebookCatalog[]>>() {
		}.getType());
		BluebookCatalog[] body = result.getBody();
		return body;
	}
}
